//package com.galaxy.mino;
//
//import io.minio.*;
//import io.minio.errors.*;
//import io.minio.messages.Item;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.ui.ModelMap;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.io.*;
//import java.nio.charset.StandardCharsets;
//import java.security.InvalidKeyException;
//import java.security.NoSuchAlgorithmException;
//import java.util.ArrayList;
//import java.util.Collections;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * minio 测试控制器
// * @author anjie
// * @email anjie@032t.com
// * @date 2020年8月10日
// */
//@RestController
//@RequestMapping("/minio")
//public class MimioController {
//
//    @Autowired
//    MinioClient minioClient;
//
//    @Value("${minio.bucketName}")
//    private String bucketName;
//
//
//    @RequestMapping("/index")
//    public String index(String path, String openfile, ModelMap mmap) throws IOException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, ServerException, InternalException, XmlParserException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException {
//
//        mmap.put("dirlist", getDirList(path));
//        mmap.put("openfile",openfile);
//
//        return "minio/index";
//
//    }
//
//
//    @RequestMapping("/getdirlist")
//    public ArrayList<Map<String,Object>> getDirList(String dir) throws IOException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, ServerException, ErrorResponseException, XmlParserException, InvalidBucketNameException, InsufficientDataException, io.minio.errors.InternalException {
//
//        return listObjects(dir);
//
//    }
//
//    @RequestMapping("/save")
//    public Object save(String filepath,String content) throws IOException, InvalidKeyException, InvalidResponseException, InsufficientDataException, NoSuchAlgorithmException, ServerException, io.minio.errors.InternalException, XmlParserException, InvalidBucketNameException, ErrorResponseException {
//        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8.name()));
//        minioClient.putObject(
//                PutObjectArgs.builder().bucket(bucketName).object(filepath).stream(
//                        byteArrayInputStream, byteArrayInputStream.available(), -1)
//                        .build()
//        );
//
//        return "添加成功!";
//    }
//
//    @RequestMapping("/getfile")
//    public Object getFile(String filepath) throws IOException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, ServerException, ErrorResponseException, XmlParserException, InvalidBucketNameException, InsufficientDataException, io.minio.errors.InternalException {
//
//        InputStream inputStream = fileIo(filepath);
//        ByteArrayOutputStream result = new ByteArrayOutputStream();
//        byte[] buffer = new byte[1024];
//        int length;
//        while ((length = inputStream.read(buffer)) != -1) {
//            result.write(buffer, 0, length);
//        }
//        String str = result.toString(StandardCharsets.UTF_8.name());
//        return str;
//
//    }
//
//    public InputStream fileIo(String objname) throws IOException, InvalidKeyException, InvalidResponseException, InsufficientDataException, NoSuchAlgorithmException, ServerException, io.minio.errors.InternalException, XmlParserException, InvalidBucketNameException, ErrorResponseException {
//
//        InputStream object = minioClient.getObject(
//                GetObjectArgs.builder().bucket(bucketName)
//                        .object(objname).build()
//        );
//
//        return object;
//    }
//
//    //获取指定文件列表
//    public ArrayList<Map<String,Object>> listObjects(String prefix) throws IOException, InvalidKeyException, InvalidResponseException, InsufficientDataException, NoSuchAlgorithmException, ServerException, io.minio.errors.InternalException, XmlParserException, InvalidBucketNameException, ErrorResponseException {
//
//        Iterable<Result<Item>> results = minioClient.listObjects(
//
//                ListObjectsArgs.builder()
//                        .bucket("my-bucketname")
//                        .recursive(false)
//                        .prefix(prefix)
//                        .build()
//
//        );
//        ArrayList<Map<String,Object>> items = new ArrayList<>();
//
//        for(Result<Item> i:results){
//            Item item = i.get();
//            HashMap<String, Object> data = new HashMap<>();
//            data.put("isDir",item.isDir());
//            data.put("objname", item.objectName());
//            String[] split = item.objectName().split("/");
//            data.put("name",split[split.length-1]);
//            data.put("lastModified",!item.isDir()?item.lastModified():null);
//            data.put("size",item.size());
//            items.add(data);
//        }
//        Collections.reverse(items);
//        return items;
//
//    }
//
//}
